<template>
  <div ref="app" id="app">
    <keep-alive>
      <router-view></router-view>
    </keep-alive>
  </div>
</template>

<script>
export default {
  name: 'app',
  created () {
  },
  mounted () {
    // 离线
    window.onoffline = () => {
      this.handleNetWorkChange({
        name: '网易云音乐',
        title: '网易云音乐',
        message: '网络连接中断'
      })
    }
    // 上线
    window.ononline = () => {
      this.handleNetWorkChange({
        name: '网易云音乐',
        title: '网易云音乐',
        message: '网络连接成功'
      })
    }
  },
  methods: {
    // 网络变化
    handleNetWorkChange ({ name, title, message }, status = true) {
      let networkNotification = new Notification(name, {
        title,
        body: message,
        icon: 'public/images/icon.ico'
      })
    }
  }
}
</script>

<style lang="scss">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
